package com.zelin.controller;

import com.zelin.pojo.PageResult;
import com.zelin.pojo.R;
import com.zelin.pojo.Student;
import com.zelin.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ------------------------------
 * 功能：
 * 作者：WF
 * 微信：hbxfwf13590332912
 * 创建时间：2021/9/14-15:13
 * ------------------------------
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //1. 查询所有学生
    @GetMapping("list")
    public R findAll(){
        List<Student> studentList = studentService.findAll();
        return R.ok().data("students",studentList);
    }

    //2. 分页查询
    @GetMapping("findByPage")
    public R findByPage(int page,int pageSize){
        PageResult<Student> pageResult = studentService.findByPage(page,pageSize);
        return R.ok().data("rs",pageResult);
    }

    //3. 条件查询带分页
    @PostMapping("search")
    public R search(int page, int pageSize, @RequestBody Student student){
        PageResult<Student> pageResult = studentService.search(page,pageSize,student);
        return R.ok().data("rs",pageResult);
    }

    //4. 添加学生
    @PostMapping("add")
    public R add(@RequestBody Student student){
        studentService.add(student);
        return R.ok();
    }

    //5. 修改学生
    @PostMapping("update")
    public R update(@RequestBody Student student){
        studentService.update(student);
        return R.ok();
    }

    //6. 删除学生
    @GetMapping("delete")
    public R delete(Integer sid){
        studentService.delete(sid);
        return R.ok();
    }
}
